package com.codeduck.config;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.transaction.PlatformTransactionManager;

import javax.sql.DataSource;

/**
 * @author: <a href="mailto:codeduck@163.com">code-duck</a>
 * @date: 2025/7/30
 */
@Configuration
public class QuartzConf {
    @Bean("clusteredScheduler")
    public SchedulerFactoryBean initClusteredSchedulerFactoryBean(DataSource dataSource) {
        SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();
        schedulerFactoryBean.setSchedulerName("cluster-scheduler");
        schedulerFactoryBean.setConfigLocation(new ClassPathResource("quartz/clustered_quartz.properties"));
        schedulerFactoryBean.setOverwriteExistingJobs(true);
//        schedulerFactoryBean.setDataSource(dataSource);
        // 优雅停机
        schedulerFactoryBean.setWaitForJobsToCompleteOnShutdown(true);
        schedulerFactoryBean.setApplicationContextSchedulerContextKey("applicationContext");

        return schedulerFactoryBean;
    }
}
